/**
 * 
 */
package com.sidom.movieIndexer.service.ouput;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.sidom.movieIndexer.domain.Movie;

/**
 * {@inheritDoc}.
 * @author Siebe
 */
@Service
public class HtmlOutputService implements OutputService{
	/**
	 * Logger for {@link HtmlOutputService}.
	 */
	private Log log = LogFactory.getLog(HtmlOutputService.class);
	
	/**
	 * {@inheritDoc}.
	 */
	@Override
	public String createOutPut(List<Movie> movies) {
		log.info("Making html output of movies");
		StringBuilder builder = new StringBuilder();
		builder.append("<html>");
		builder.append("<table>");
		for (Movie movie : movies) {
			if(movie.getImdbResult()!=null){
				builder.append("<tr>");
				builder.append("<td><img src=" + movie.getImdbResult().getCoverUrl() + "/></td>");
				builder.append("<td>" + movie.getImdbResult().getPlot() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getReleaseDate() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getTagLine() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getTitle() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getUserRating() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getUserReviews() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getYear() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getCastMembers() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getDirector() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getGenres() + "</td>");
				builder.append("<td>" + movie.getImdbResult().getPlotKeyWords() + "</td>");
				builder.append("</tr>");
			}
		}
		builder.append("</table>");
		builder.append("<html>");
		return builder.toString();
	}
}
